package distributedbank.server.messages;

import distributedbank.gui.messages.BalanceResponse;
import distributedbank.server.BankBranch;

/**
 * A request to display the amount of cash in an account.
 */
public class Query
        extends Transaction {
    public static final long serialVersionUID = 1;

    public Query(int branchId, int accountId, int transactionId, int fromPort) {
        super(branchId, accountId, transactionId, fromPort);
    }

    @Override
    public Acknowledgment runRequestSilent(BankBranch bankBranch) {
        System.out.println("Querying account " + this.accountId + " at branch "
                + this.branchId);
        int balance = bankBranch.getAccount(this.accountId).query(
                this.transactionId);
        BalanceResponse message = new BalanceResponse(this.transactionId,
                this.branchId, this.accountId, balance);
        return message;
    }
}
